package cn.jxau.web.controller;

import org.springframework.beans.factory.annotation.Autowired;

import cn.jxau.bean.vo.JsonResult;
import cn.jxau.service.ArticleCommentService;
import cn.jxau.service.ArticleService;
import cn.jxau.service.ArticleTypeService;
import cn.jxau.service.IndexService;
import cn.jxau.service.UserCollectionsService;
import cn.jxau.service.UserService;
import cn.jxau.service.replyService;

/**
 * Base Controller
 * @author licho
 *
 */
public class BaseController {
	@Autowired
	protected IndexService indexService;
	@Autowired
	protected UserService userService;
	@Autowired
	protected ArticleService articleService;
	@Autowired
	protected ArticleTypeService articleTypeService;
	@Autowired
	protected ArticleCommentService articleCommentService; 
	@Autowired
	protected replyService replyService; 
	@Autowired
	protected UserCollectionsService collectionsService; 
	  /**
     * 渲染失败数据
     *
     * @return result
     */
    protected JsonResult renderError() {
        JsonResult result = new JsonResult();
        result.setSuccess(false);
        result.setStatus("500");
        return result;
    }

    /**
     * 渲染失败数据（带消息）
     *
     * @param msg 需要返回的消息
     * @return result
     */
    protected JsonResult renderError(String msg) {
        JsonResult result = renderError();
        result.setMsg(msg);
        return result;
    }

    /**
     * 渲染成功数据
     *
     * @return result
     */
    protected JsonResult renderSuccess() {
        JsonResult result = new JsonResult();
        result.setSuccess(true);
        result.setStatus("200");
        return result;
    }

    /**
     * 渲染成功数据（带信息）
     *
     * @param msg 需要返回的信息
     * @return result
     */
    protected JsonResult renderSuccess(String msg) {
        JsonResult result = renderSuccess();
        result.setMsg(msg);
        return result;
    }

    /**
     * 渲染成功数据（带数据）
     *@param 数据对应的属性key
     * @param obj 需要返回的对象
     * @return result
     */
    protected JsonResult renderSuccess(String name,Object obj) {
        JsonResult result = renderSuccess();
        result.addData(name, obj);
        return result;
    }
}
